import {type baseResponse, type listResponse, type optionsType, type paramsType, useAxios} from "@/api/index";


export interface emailLoginRequest {
    user_name: string
    password: string
}

export function emailLoginApi(data: emailLoginRequest): Promise<baseResponse<string>> {
    return useAxios.post("/api/email_login", data)
}


export interface userInfoType {
    "userID": number
    "nickname": string
    "role": number
    "createdAt": string
    "avatar": string
    "tel": string
    "email": string
    "scope": number
    "registerSource": number
    isPwdBind: boolean // 是否绑定密码
}

export function userInfoApi(): Promise<baseResponse<userInfoType>> {
    return useAxios.get("/api/userinfo")
}

export function userLogoutApi(): Promise<baseResponse<string>> {
    return useAxios.get("/api/logout")
}

export interface userListType {
    "id": number
    "createdAt": string
    "nickname": string
    "username": string
    "tel": string
    "email": string
    "openID": string
    "registerSource": number
    "avatar": string
    "scope": number
    "role": number
    "money": number
    "userCreateAIRoleCount": number
    "userSessionCount": number
    "userChatCount": number

}

// 用户列表
export function userListApi(params?: paramsType): Promise<baseResponse<listResponse<userListType>>> {
    return useAxios.get("/api/users", {params})
}

export interface userAdminUpdateInfoRequest {
    "nickname": string
    "userID": number
    "role": number
    "avatar": string
}

//  管理员更新用户信息
export function userAdminUpdateInfoApi(data: userAdminUpdateInfoRequest): Promise<baseResponse<string>> {
    return useAxios.put("/api/userinfo/admin", data)
}


export interface userUpdateInfoRequest {
    "nickname"?: string
    "avatar"?: string
}

export function userUpdateInfoApi(data: userUpdateInfoRequest): Promise<baseResponse<string>> {
    return useAxios.put("/api/userinfo", data)
}





export function articleCategoryOptionsApi(params?: paramsType): Promise<baseResponse<optionsType[]>> {
    return useAxios.get("/api/categorys")
}


export function userOptionsApi(): Promise<baseResponse<optionsType[]>> {
    return useAxios.get("/api/users/options")
}

export enum userAccountBindType {
    email = 1, // 0
    tel = 2, // 1
}



export interface userBindAccountType {
    "value": string
    "bindType": userAccountBindType
    "code"?: string
    "step": 1 | 2
    "captcha"?: string
    "captchaID"?: string
}

export function userBindAccountApi(data: userBindAccountType): Promise<baseResponse<string>> {
    return useAxios.post("/api/bind_account", data)
}



export interface userUpdatePwdType {
    "oldPwd": string
    "pwd": string
    rePwd?: string
}

export function userUpdatePwdApi(data: userUpdatePwdType): Promise<baseResponse<string>> {
    return useAxios.post("/api/update_password", data)
}

export interface userBindPwdType {
    "pwd": string
    rePwd?: string
}

export function userBindPwdApi(data: userBindPwdType): Promise<baseResponse<string>> {
    return useAxios.post("/api/bind_password", data)
}

export interface userLoginListType {
    "id": number
    "createdAt": string
    "userID": number
    "ip": string
    "addr": string
    "token": string
    "ua": string
    "lose": boolean
}

export interface userLoginListRequest  extends  paramsType{
    type: number // 1 普通用户  2 管理员
}

export function userLoginListApi(params?: userLoginListRequest): Promise<baseResponse<userLoginListType[]>> {
    return useAxios.get("/api/user_login", {params})
}

// 设备下线
export function userLoginLoseApi(id: number):Promise<baseResponse<string>>{
    return useAxios.post("/api/user_login", {id})
}

export function userLoginAdminLoseApi(id: number):Promise<baseResponse<string>>{
    return useAxios.post("/api/user_login/admin", {id})
}


export interface userLoginPwdType {
    "val": string
    "pwd": string
    "loginType": 1|2|3|4|5|6 //  1 邮箱 2 手机号  4 用户名
    "captcha": string
    "captchaID": string
}

export function userLoginPwdApi(data: userLoginPwdType): Promise<baseResponse<string>> {
    return useAxios.post("/api/password_login", data)
}


export interface userLoginCodeType {
    "step": 1 | 2
    "captcha"?: string
    "value": string
    "registerType": 1 | 2
    "captchaId"?: string
    "code"?: string
}

export function userLoginCodeApi(data: userLoginCodeType):Promise<baseResponse<string>>{
    return  useAxios.post("/api/login", data)
}


export interface wxloginCreateResponse {
    qruri: string//二维码地址
    ticket: string //二维码标识
}



export function getWxQrcodeApi(): Promise<baseResponse<wxloginCreateResponse>> {
    return useAxios.get("/api/wxqrcode");
}

export function getWxLoginOkApi(ticket:string): Promise<baseResponse<string>> {
    return useAxios.get("/api/wxqrgettoken", {
        params: { ticket }
    });
}


export interface userCardInfoType {
    "nickname": string
    "scope":  number
    "chatCount": number
    "createRoleCount": number
}

export function userCardInfoApi():Promise<baseResponse<userCardInfoType>>{
    return useAxios.get("/api/userinfo/card")
}